//
//  StatusRetweetedCell.m
//  OCMicroBlog
//
//  Created by 002 on 15/11/8.
//  Copyright © 2015年 002. All rights reserved.
//

#import "StatusRetweetedCell.h"
#import "UIButton+Extention.h"
#import "UILabel+Extention.h"
#import "masonry.h"


@interface StatusRetweetedCell ()

// 背景图片
@property(nonatomic,strong) UIButton *backButton;

// 转发微博标签
@property(nonatomic,strong) UILabel *retweetedLabel;

@end

@implementation StatusRetweetedCell

- (void)setViewModel:(StatusViewModel *)viewModel {
    [super setViewModel:viewModel];
    
    self.retweetedLabel.text = viewModel.retweetedText;
    
    // 修改配图视图顶部位置
    [self.pictureView mas_updateConstraints:^(MASConstraintMaker *make) {
        CGFloat offset = self.viewModel.thumbnailUrls.count > 0 ? StatusCellMagrin : 0;
        make.top.equalTo(self.retweetedLabel.mas_bottom).offset(offset);
    }];
}

// 重写父类 |设置界面|
- (void)setupUI {
    
    [super  setupUI];
    
    // 1. 添加控件
    [self.contentView insertSubview:self.backButton belowSubview:self.pictureView];
    [self.contentView insertSubview:self.retweetedLabel aboveSubview:self.backButton];

    // 2. 布局
    // 1) 背景按钮
    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(StatusCellMagrin);
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.bottom.equalTo(self.bottomView.mas_top);
    }];
    
    // 2) 转发标签
    [self.retweetedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backButton.mas_top).offset(StatusCellMagrin);
        make.left.equalTo(self.backButton.mas_left).offset(StatusCellMagrin);
    }];
    
    // 3) 配图视图
    [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.retweetedLabel.mas_bottom).offset(StatusCellMagrin);
        make.left.equalTo(self.retweetedLabel.mas_left);
        make.width.equalTo(@300);
        make.height.equalTo(@90);
    }];
}

#pragma mark - 懒加载
// 背景图片
- (UIButton *)backButton {
    if (!_backButton) {
        _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backButton sizeToFit];
        _backButton.backgroundColor = [[UIColor alloc] initWithWhite:0.95 alpha:1.0];
    }
    return _backButton;
}

// 转发微博标签
- (UILabel *)retweetedLabel {
    if (!_retweetedLabel) {
        _retweetedLabel = [UILabel initWithTitle:@"转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博" fontSize:14 color:[UIColor darkGrayColor] screenInset:StatusCellMagrin];
    }
    return _retweetedLabel;
}

@end
